package com.cx.base.view.activity;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable;

import butterknife.ButterKnife;

/**
 * Author by ziv, Email wuming5445@dingtalk.com, Date on 2020/9/29.
 */
public abstract class BaseActivity extends IActivity {
    protected ViewGroup mRootView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (!isInit())
            return;

        initParams(getIntent().getExtras());
        LayoutInflater inflater = getLayoutInflater();
        inflater.inflate(initLayoutRes(), null);
        mRootView = (ViewGroup) initByViewBind(inflater, null);
        if (mRootView == null)
            mRootView = (ViewGroup) inflater.inflate(initLayoutRes(), null);
        setContentView(mRootView);
        ButterKnife.bind(this);
        initViewAndData();
        bindPresenter();
        initViewEvent();
    }


    protected View initByViewBind(LayoutInflater inflater, @Nullable ViewGroup container) {
        return null;
    }

    protected boolean isInit() {
        return true;
    }

    protected void initParams(Bundle bundle) {

    }

    protected abstract void initViewAndData();

    protected void initViewEvent() {

    }

    protected abstract void bindPresenter();

    protected abstract @LayoutRes
    int initLayoutRes();
}
